package com.example.pages;

import org.openqa.selenium.By;
import java.util.List;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.FindBys;

/**
 * Created with IntelliJ IDEA.
 * User: home
 * Date: 11/3/12
 * Time: 12:38 PM
 * To change this template use File | Settings | File Templates.
 */
public class UserManagementPage extends InternalPage {

    @FindBy(id = "username")
    public WebElement userNameField;

    @FindBy(name = "password")
    public WebElement passwordField;

    @FindBy(name = "email")
    public WebElement emailField;

    @FindBy(name = "password2")
    public WebElement confirmPasswordField;

    @FindBy(name = "submit")
    public WebElement saveButton;

    @FindBy(xpath = "//div[@class='content']/table/tbody/tr[2]/td[3]/a")
    public WebElement newUser;

    public boolean isUserAdded(String email) {
        return newUser.getText().trim().equals(email);
    }

    @FindBy(xpath = "//div[contains(@class, 'content')]//tr[2]/td[2]/a")
    public WebElement findUser;

    @FindBy(xpath = "//div[contains(@class, 'content')][2]/h3")
    public WebElement usersTitle;

    public boolean isUsersTableDisplayed() {
        return usersTitle.getText().equals("Users");
    }

    @FindBy(xpath = "(//img[@alt='Remove'])")
    public WebElement findUserToDelete;
//
//    @FindBy(xpath = "//div[@class = 'content']/table//tr")
//    public WebElement getTotalUsersNumberInTable;

    public List<WebElement> getTotalUsersNumberInTable(WebDriver driver)
    {
        return driver.findElements(By.xpath("//div[@class = 'content']/table/tbody/tr"));
    }

}
